package v1

import (
	"net/http"
	"rustdesk_api_server/api/request"
	"rustdesk_api_server/api/response"
	"rustdesk_api_server/api/services"

	"github.com/gin-gonic/gin"
)

type UserApi struct{}

func (u *UserApi) CurrentUser(ctx *gin.Context) {
	user_id := ctx.GetInt("user_id")
	user, err := services.Users.GetByUserId(uint(user_id))

	var form request.CurrentUserForm
	ctx.ShouldBindJSON(&form)

	if err != nil {
		ctx.JSON(http.StatusOK, response.JsonResult{
			Code:  -1,
			Error: "错误",
		})
		ctx.Abort()
		return
	} else {
		ctx.JSON(http.StatusOK, gin.H{
			"name": user.Username,
		})
	}
}
